package www.rlicker.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import www.rlicker.model.GuidePicture;
import www.rlicker.model.Parame;
import www.rlicker.mybatis.Criteria;
import www.rlicker.service.IGuidePictureService;
import www.rlicker.service.IParameService;
import www.rlicker.utils.JsonResult;

@Controller
@RequestMapping(value="/system")
public class SystemController {
	
	@Autowired
	private IGuidePictureService service;
	
	
	@Autowired
	private IParameService parameService;
	
	@RequestMapping(value="/abouts")
	public String showAbouts(){
		return "system/aboutUs";
	}
	
	@RequestMapping(value="/carouse")
	public String showCarouse(){
		return "system/carouselUpload";
	}
	
	@RequestMapping(value="/start")
	public String startUpload(){
		return "system/startUpload";
	}
	
	@RequestMapping(value="/agreement")
	public String userAgreement(){
		return "system/userAgreement";
	}
	
	@RequestMapping(value="/privacy")
	public String privacyAgreement(){
		return "system/privacyAgreement";
	}
	
	@RequestMapping(value="/video")
	public String videoManagement(){
		return "system/videoManagement";
	}
	
	@RequestMapping(value="/rule")
	public String ruleManagement(){
		return "system/ruleManagement";
	}
	
	@RequestMapping(value="querypage")
	@ResponseBody
	public List<GuidePicture> queryPage(){
		Criteria<GuidePicture> param = new Criteria<GuidePicture>();
		param.addParam("type", 1);
		return service.queryPageList(param);
	}
	
	@RequestMapping(value="/canshu")
	public String canshu(ModelMap map){
		map.put("parame", parameService.queryEntity());
		return "system/canshuList";
	}
	
	@ResponseBody
	@RequestMapping(value="/update" , method = { RequestMethod.POST })
	public JsonResult update(HttpServletRequest request){
		JsonResult jr = JsonResult.newInstance(); 
		Criteria<Parame> param = new Criteria<Parame>();
		Parame parame = new Parame();
		parame.setParamValue(request.getParameter("paramValue"));
		param.setRecord(parame);
	    String ret = parameService.update(param);
		return ret == null ? jr.declareSuccess() : jr.declareFailure(ret); 
	}

}
